/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jsf.session;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import jpa.entities.Classes;
import jpa.entities.Staff;
import jpa.entities.Students;

/**
 *
 * @author KenShin
 */
@Stateless
public class StudentsFacade extends AbstractFacade<Students> {
    @PersistenceContext(unitName = "SupportiveLearning-ejbPU")
    private EntityManager em;
    private Students student;
    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public StudentsFacade() {
        super(Students.class);
    }
    public Students checkStudentValid(String UserName, String Password) {
        student = null;
         List<Students> results = em.createQuery("SELECT s FROM Students s WHERE s.userName = :userName AND s.password = :password")
           .setParameter("userName", UserName)
           .setParameter("password", Password)
           .getResultList();
         
         if (!results.isEmpty() ) {
           student = results.get(0);
        }
        return student;
    }
    public Students getProfile(String UserName)
    {
        List<Students> results = em.createQuery("SELECT s FROM Students s WHERE s.userName = :userName")
           .setParameter("userName", UserName)
           .getResultList();
         
         if (!results.isEmpty() ) {
           student = results.get(0);
        }
        return student;
    }
    public List<Students> findStudenteByClassesId(Classes classes) {
        
            List<Students> results = em.createQuery("SELECT s FROM Students s WHERE s.classId = :classId")
           .setParameter("classId", classes)
           .getResultList();
         
        return results;
    }
}
